package com.ymy.thinking.in.spring.bean.lifecycle;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import thinking.in.spring.ioc.overview.domain.User;

/**
 * 合并 Bean Definition 示例
 * <p>
 * Child Bean Definition 和 Parent Bean Definition 合并后会变成 {@link RootBeanDefinition}
 *
 * @author Ringo
 * @date 2022/2/6 12:46
 */
public class MergedBeanDefinitionDemo {

    public static void main(String[] args) {
        final String location = "classpath:META-INF/dependency-look-context.xml";
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
        XmlBeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader(beanFactory);
        int count = beanDefinitionReader.loadBeanDefinitions(location);
        System.out.println("读到" + count + "个 Bean Definition.");

        System.out.println(beanFactory.getMergedBeanDefinition("superUser").getClass().getName());
        System.out.println(beanFactory.getMergedBeanDefinition("user").getClass().getName());

        System.out.println(beanFactory.getBean("user", User.class));

    }

}
